Replacing nested loop in JavaScript

visit shbcf.ru